<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/2
 * Time: 2:42 PM
 */

namespace App\Entities;

class UserEntity extends ABaseEntity
{
    public function __construct(UserModel $model)
    {
        $this->model = $model;
    }

    /**
     * 通过手机号查找，或者新建一个
     * @param string $phone
     * @return UserEntity
     */
    public static function findByPhone(string $phone)
    {
        $model = UserModel::where('phone', $phone)->first();
        if (is_null($model)) {
            return null;
        }
        return new UserEntity($model);
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->model->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->model->name;
    }

    /**
     * @param $name string
     */
    public function setName($name)
    {
        $this->model->name = $name;
    }

    /**
     * @param $password string
     */
    public function setPassword($password)
    {
        $this->model->password = $password;
    }

    /**
     * @param $phone
     */
    public function setPhone($phone)
    {
        $this->model->phone = $phone;
    }

    /**
     * @param $phone_verified_at
     */
    public function setPhoneVerifiedAt($phone_verified_at)
    {
        $this->model->phone_verified_at = $phone_verified_at;
    }

    /**
     * @param $createAt int
     */
    public function setCreateAt($createAt)
    {
        $this->model->created_at = $createAt;
    }

    /**
     * @return string
     */
    public function getPhone()
    {
        return $this->model->phone;
    }

    /**
     * @return string
     */
    public function getPhoneVerifiedAt()
    {
        return $this->model->phone_verified_at;
    }

    /**
     * @return string
     */
    public function getLastLoginAt()
    {
        return (string)$this->model->last_login_at;
    }

    /**
     * @param string $lastLoginAt
     */
    public function setLastLoginAt(string $lastLoginAt)
    {
        $this->model->last_login_at = $lastLoginAt;
    }

    /**
     * @return int
     */
    public function getEnabled()
    {
        return (int)$this->model->enabled;
    }

    /**
     * @return int
     */
    public function getCreatedAt()
    {
        return $this->model->created_at;
    }

    /**
     * @param $user_channelid int
     */
    public function setUserChannelid($user_channelid)
    {
        $this->model->user_channelid = $user_channelid;
    }

    /**
     * @return int
     */
    public function getUserChannelid()
    {
        return $this->model->user_channelid;
    }

    /**
     * @return string
     */
    public function getOpenid(): string
    {
        return (string)$this->model->openid;
    }

    /**
     * @param string $openid
     */
    public function setOpenid(string $openid): void
    {
        $this->model->openid = $openid;
    }
}
